<template>
	<view>
		
		<!-- 账号名称 -->
		<view class="info_item">
			<text>个人昵称</text>
			<input placeholder="请输入昵称" v-model="nickname"  style="margin-top: 39rpx;"
				placeholder-style="font-size:30rpx" />
		</view>
		
		<view class="info_item">
			<text>账号</text>
			<input placeholder="请输入账号" v-model="username"  style="margin-top: 39rpx;"
				placeholder-style="font-size:30rpx" />
		</view>
		
		<!-- 头像 -->
		<view class="info_item">
			<view>头像</view>
			<image v-if="avatar == ''" src="/static/client/tianjia.png"
				style="width: 78rpx;height: 78rpx;margin-top: 29rpx;"></image>
			<image v-else :src="avatar"
				style="border-radius: 39px; width: 78rpx;height: 78rpx;margin-top: 29rpx;"></image>
			<view style="position: absolute;top: 80rpx; left: 100rpx;" @click="selectImg">
				<image src="/static/firm/icon_sc.png" style="width: 25rpx; height: 19rpx;">
				</image>
				<text style="font-size: 20rpx; color: #128BF1;margin-left: 10rpx;">点击上传图片</text>
			</view>
		</view>
		<view class="btn-box">
			<view class="login_btn all_text_center" @click="editUser()">
				完成
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				token: '',
				member_id: '',
				memberlist: [],
				checkboxValue1: '',
				username:'',
				nickname:'',
				avatar:'',
				is_outuser: '',
				
				

				gid: '',

				ids: ''
			}
		},
		onLoad(val) {
			this.token = uni.getStorageSync('chat_token') || ''
			this.member_id = uni.getStorageSync('chat_member_id') || ''
			this.is_outuser = uni.getStorageSync('chat_is_outuser') || ''
			this.getMemberList()
		},
		onShow() {
			
		},
		methods: {
			// 上传头像
			selectImg() {
				var that = this
				uni.chooseImage({
					count: 1, // 最多可以选择的图片张数，默认9
					sizeType: ['original', 'compressed'], //original 原图，compressed 压缩图，默认二者都有
					sourceType: ['album', 'camera'], //album 从相册选图，camera 使用相机，默认二者都有。如需直接开相机或直接选相册，请只使用一个选项
					success: async (res) => {
						const tempFilePaths = res.tempFilePaths;
						// that.phone = res.tempFilePaths[0]
						uni.uploadFile({
							// url: 'https://test.control.sxpz.vip/index.php/AppApi/Chat/uploadImg',
							url: 'https://control.sxpz.vip/index.php/AppApi/Chat/uploadImg',
							filePath: tempFilePaths[0],
							name: 'file',
							formData: {
								'member_id': this.member_id,
								'token': this.token,
							},
							success: uploadFileRes => {
								const result = JSON.parse(uploadFileRes.data)
								this.avatar = result.datas.img_url
							}
						})
					}
				});
			},

			async editUser() {

				const res = await this.$myRequest({
					url: 'Chat/member_info_edit',
					method: 'POST',
					data: {
						member_id: this.member_id,
						token: this.token,
						is_outuser:'1',
						avatar:this.avatar,
						username:this.username,
						nickname:this.nickname
					},
				});
				if (res.data.code != 200) return uni.showToast({
					title: res.data.datas.msg,
					icon: 'none'
				})

				uni.showToast({
					title: res.data.datas.msg,
					icon: 'none'
				})

				setTimeout(() => {
					uni.navigateBack({
						delta: 1
					})
				}, 1000);
			},

			async getMemberList() {
				const res = await this.$myRequest({
					url: 'Chat/member_info',
					method: 'POST',
					data: {
						token: this.token,
						member_id: this.member_id,
						is_outuser:'1'
					},
				});
				if (res.data.code != 200) return uni.showToast({
					title: res.data.datas.msg,
					icon: 'none'
				})
				this.avatar = res.data.datas.avatar
				this.username = res.data.datas.username
				this.nickname = res.data.datas.nickname
			},
		}
	}
</script>

<style lang="scss" scoped>
	page {
		display: flex;
		justify-content: center;
		align-items: center;
	}
	
	.bottom {
		width: 100%;
		height: 88rpx;
		position: absolute;
		bottom: 0;
	}
	
	.bottom_btn {
		width: 375rpx;
		height: 88rpx;
		margin-left: 0;
		border-radius: 0;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}
	
	.texta {
		width: 690rpx;
		height: 305rpx;
		background: #F7F7F7;
		margin-top: 30rpx;
	
	}
	
	.info_item {
		width: 690rpx;
		height: auto;
		border-bottom: 1rpx solid #E3E3E3;
		margin-left: 30rpx;
		margin-top: 44rpx;
		position: relative;
	}
	
	.head_text {
		width: 100%;
		height: 128rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 160rpx;
		text-align: center;
		border-bottom: 19rpx solid #F7F7F7;
	}

	.btn-box {
		display: flex;
		justify-content: center;
		align-items: center;

		.login_btn {
			width: 540rpx;
			height: 80rpx;
			background: #008BFE;
			color: #ffffff;
			box-shadow: 0px 1px 4px 1px rgba(0, 0, 0, 0.4);
			border-radius: 12rpx;
			font-size: 36rpx;
			margin-top: 60rpx;
		}
	}
</style>
